import {
    UPDATE_WEATHER,
    LOADING_STATE,
    POSITION_ID
} from './mutations_type'
export default {
    // 字体背景、字体颜色改变
    // replace_appBacColor(state, curr_switch) {
    //     switch (curr_switch) {
    //         case true:
    //             state.appBac_color = '#000';
    //             state.global_fontColor = 'rgba(225, 225, 225, .8)';
    //             state.leftNavBarColor = '#333';
    //             state.cardBacImg = true;
    //             state.lifeIndexBacColor = true;
    //             state.logoUrls = require('../assets/img/light.png');
    //             break;
    //         case false:
    //             state.appBac_color = '#fff';
    //             state.global_fontColor = 'rgba(0, 0, 0, .8)';
    //             state.leftNavBarColor = '#fff';
    //             state.cardBacImg = false;
    //             state.lifeIndexBacColor = false;
    //             state.logoUrls = require('../assets/img/logo-dark.png');
    //             break;
    //     }
    // },

    [UPDATE_WEATHER](state, payload) {
        console.log(payload);
        // 当前天气数据
        state.positionCity = payload.currDay_data.data.now;
        // 城市数据
        state.cityPosition = payload.city_data.data.location[0];
        // 生活指数数据
        let sliceLifeIndex = payload.lifeIndex_data.data.daily;
        state.lifeIndex = [sliceLifeIndex[0], sliceLifeIndex[1], sliceLifeIndex[8], sliceLifeIndex[2], sliceLifeIndex[5], sliceLifeIndex[7], sliceLifeIndex[4], sliceLifeIndex[9]];

        // 7日天气预告数据
        state.forecast.days = payload.sevenDay_data.data.daily;
        // 将需要数据清除包装
        // for (let i = 0; i < state.forecast.days.length; i++) {
        //     let ri_arr = [],
        //         ri_objs = {
        //             ri_c: '',
        //             ri_l: '',
        //             yue_c: '',
        //             yue_l: '',
        //             b_feng_x: '',
        //             b_feng_d: '',
        //             y_feng_x: '',
        //             y_feng_d: ''
        //         },
        //         forecast = state.forecast.days[i];
        //     // 日出/日落
        //     ri_objs.ri_c = forecast.sunrise
        //     ri_objs.ri_l = forecast.sunset
        //     // 月出/月落
        //     ri_objs.yue_c = forecast.moonrise
        //     ri_objs.yue_l = forecast.moonset
        //     // 白天风向/等级
        //     ri_objs.b_feng_x = forecast.windDirDay
        //     ri_objs.b_feng_d = forecast.windScaleDay
        //     // 夜晚风向/等级
        //     ri_objs.y_feng_x = forecast.windDirNight
        //     ri_objs.y_feng_d = forecast.windScaleNight
        //     ri_arr.push(ri_objs)
        //     state.detailCardData.push(ri_arr)
        // }
        // // 保存在共享对象里面
        // console.log(state.detailCardData);

        state.forecast.weekdays.splice(2, 5);
        const weekDay = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
        for (let i = 2; i < state.forecast.days.length; i++) {
            state.forecast.weekdays.push(weekDay[new Date(state.forecast.days[i].fxDate).getDay()]);
        }

        // 天气预警
        state.warningStateArr = payload.warning_data.data.warning;
        state.warningStatePlatformName = state.warningStateArr.length ? state.warningStateArr[0].sender : '没有预警';

        // console.log(state.warningStatePlatformName);
        // 未来24小时天气预告
        state.hoursInfoData = payload.hours_data.data.hourly;
        // 
        state.current_air = payload.air_data.data.now;
    },
    popupFn(state, payload) {
        state.is_show = payload;
    },
    // 根据索引值来获取相对于的数据数组
    // payload: 参数是current_Index
    // 分配到sevenCard子组件事件
    // detailIndex(state, payload) {
    //     state.detailCardItemData = state.detailCardData[payload]
    // },

    // 单项生活指数
    itemLifeIndexData(state, payload) {
        state.itemLifeIndex = state.lifeIndex.filter(item => {
            return item.type === payload
        })
    },
    // actions 共享事件
    [LOADING_STATE](state, payload) {
        state.is_loading = payload;
    },
    // 城市定位
    [POSITION_ID](state, payload) {
        state.isCityPosition = payload;
    },
}